package 机试题16年;

import java.util.Arrays;

/**
 * Created by hest0 on 2017/4/20.
 */
public class 顺时针旋转矩阵 {
    public static void main(String[] args) {
        int[][] a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

        int[][] ints = new Rotate().rotateMatrix(a, a.length);
        System.out.println(Arrays.deepToString(ints));
    }

    public static class Rotate {
        public int[][] rotateMatrix(int[][] mat, int n) {
            int[][] temp = new int[n][n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    temp[j][n - 1 - i] = mat[i][j];
            return temp;
        }
    }

}
